//
//  ActivityStatus.swift
//  甜言蜜语
//
//  Created by yingli_yanfa_liuxingyu on 17/1/18.
//  Copyright © 2017年 wl. All rights reserved.
//

import UIKit
protocol ActivityStatusDelegate {
    func selectedStatus(text: String)
}
class ActivityStatus: UIView {
    var delegate: ActivityStatusDelegate?
    @IBOutlet weak var btnIng: UIButton!
    @IBOutlet weak var btnEnd: UIButton!
    var maxHeight: CGFloat = 0
    @IBOutlet weak var customView: UIView!
    var colorType = "进行中"
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.commonInit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        //self.commonInit()
    }
    
    
    func commonInit () {
        NSBundle.mainBundle().loadNibNamed("ActivityStatus", owner: self, options: nil)
        self.customView.frame.size.width = 111
        self.customView.width(self.width)
        self.customView.height(81)
        // self.customView.bottom(self.bottom())
        self.customView.top(0)
        self.customView.frame.origin.x = SCREEN_WIDTH - 111
        self.backgroundColor = UIColor.clearColor()
        self.alpha = 0
        
        
        let maskView:UIView = UIView.init(frame: self.bounds)
        maskView.backgroundColor = UIColor.blackColor()
        maskView.alpha = 0.5
        self.addSubview(maskView)
        
        self.addSubview(self.customView)
        let tap = UITapGestureRecognizer.init(target: self, action:#selector(ActivityStatus.tapClick(_:)))
        maskView.addGestureRecognizer(tap)
        if colorType == "进行中" {
            self.btnIng.backgroundColor = UIColor.lightGrayColor()
            self.btnEnd.backgroundColor = UIColor.whiteColor()
        } else if colorType == "已结束" {
            self.btnIng.backgroundColor = UIColor.whiteColor()
            self.btnEnd.backgroundColor = UIColor.lightGrayColor()
        }
       
        self.viewFrame()
        
    }
    
    func tapClick (sender:UITapGestureRecognizer) {
        self.closeBtnClick()
    }
    
    //MARK:view的位置
    func viewFrame() {
        
        if maxHeight == kScreen_height {
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.frame.origin.y = kScreen_height
                self.alpha = 0
            })
        } else {
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.alpha = 1
                self.top(0)
            })
        }
    }
    
    
    func closeBtnClick(){
        maxHeight = kScreen_height
        self.viewFrame()
        
    }
    
    @IBAction func btnIngClicked(sender: UIButton){
        delegate?.selectedStatus((sender.titleLabel?.text)!)
        self.btnIng.backgroundColor = UIColor.lightGrayColor()
        self.btnEnd.backgroundColor = UIColor.whiteColor()
        self.closeBtnClick()
    }
    
    @IBAction func btnEndClicked(sender: UIButton){
        delegate?.selectedStatus((sender.titleLabel?.text)!)
        self.btnIng.backgroundColor = UIColor.whiteColor()
        self.btnEnd.backgroundColor = UIColor.lightGrayColor()
        self.closeBtnClick()
        
    }

}
